<?php
/**
 * @file 5-3-0.php
 *
 * Delivers functions that are available since PHP 5.3.0.
 *
 * To make rpd work on older servers this file contains some functions
 * that are only available in PHP 5.3.x
 * It not fully represent all functions, only the ones that are needed to
 * ensure the functionality of rpd.
 *
 * http://code.google.com/p/rpd/wiki/php.php
 *
 * New BSD License
 * \n
 * Copyright (c) 2010 Rpd-Team
 *
 * @namespace  rpd
 * @since      0.1.0
 * @version    0.1.0
 */

/**
 *
 * Replaces the first array with the second.
 *
 * Existing fields of the first array will be overwritten with the ones that
 * are in the other arrays. The amount of arguments (other arrays) are not
 * limited.
 *
 * @param array $array  Array that will be replaced by reference
 * @param array $array1 One or more arrays that will be written over the first
 */
function array_replace( array &$array, array &$array1 )
{
	$args = func_get_args();
	$count = func_num_args();

	for ($i = 0; $i < $count; ++$i)
	{
		if (is_array($args[$i]))
		{
        	foreach ($args[$i] as $key => $val)
        	{
				$array[$key] = $val;
        	}
		} else {
        	trigger_error(__FUNCTION__ . '(): Argument #' . ($i+1)
        	              . ' is not an array',
			              E_USER_WARNING
			);
			return NULL;
		}
	}

	return $array;
}

function openssl_random_pseudo_bytes($length, &$strong) {

	$strong = false;

	for ($i=0; $i < $length; $i++)
	{
		$sha  = sha1(mt_rand());
		$char = mt_rand(0,30);
		$rnd .= chr(hexdec($sha[$char] . $sha[$char+1]));
	}

	return $rnd;
}

?>